/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package io.simple.core;



import simple.utils.concurrent.ConcurrentProperties;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Tom
 */
public class RequestContext {

    private final String requestPath;
    private final Map<Integer, String> pathGroups = new ConcurrentHashMap<>();
    private final ConcurrentProperties<String> responseHeaders = new ConcurrentProperties<>();
    private final ConcurrentProperties<String> requestHeaders = new ConcurrentProperties<>();
    private final ConcurrentProperties<Object> props = new ConcurrentProperties<>();
    private final long timestamp;

    public RequestContext(String requestPath, long timestamp, Map<Integer, String> pathGroups) {
        this.requestPath = requestPath;
        this.timestamp = timestamp;
        if (pathGroups != null) {
            this.pathGroups.putAll(pathGroups);
        }
    }

    public Map<Integer, String> getPathGroups() {
        return pathGroups;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public String getRequestPath() {
        return requestPath;
    }

    public ConcurrentProperties<String> getResponseHeaders() {
        return responseHeaders;
    }

    public ConcurrentProperties<String> getRequestHeaders() {
        return requestHeaders;
    }

    public ConcurrentProperties<Object> getProperties() {
        return props;
    }

    // syntax sugar
    public void setProperty(String propName, Object propVal) {
        props.set(propName, propVal);
    }

    public void addProperty(String propName, Object propVal) {
        props.add(propName, propVal);
    }

    public Object getProperty(String propName) {
        return props.get(propName);
    }

    public List<Object> getProps(String propName) {
        return props.getValues(propName);
    }

}
